{% extends 'homepage.html' %}
{% block content %}  

{% if user_is_authenticated %}
   <h1>You are {{ info.user.name }}</h1>
   <h2>Actions</h2>
   <ul><li><a href="{{ info.logout }}">Logout</a></li></ul>

{% else %}
  <h1>You are not logged in</h1>
  <div style="margin-bottom: 20px">New user? 
     <a href="{{ url_for('.register_new') }}">Register here</a>
  </div>

  <form name="login" action="{{ url_for('.login') }}" method="POST">
    <input type="hidden" name="next" value="{{ info.next }}" /> 
    <table>
      <tr><td>Name:</td>
          <td><input name="name" /></td></tr>
      <tr><td>Password:</td>
          <td><input name="password" type="password" /></td></tr>
      <tr><td>Remember:</td>
           <td><input type="checkbox" name="remember" checked>remember me for some time</td></tr>
      <tr><td class="spacing" colspan="2"/></tr>
      <tr><td /><td><button name="submit" type="submit">Login</button></td></tr>
    </table>
  </form>
{% endif %}

{% if user_is_authenticated %}
  <h2>Edit Details</h2>
  <form action="{{ url_for('.set_info') }}" method="post" name="userinfo">
    <table>
      <tr>
        <td>Your ID:</td>
        <td><a href="{{ url_for(".info", userid=info.user.id)}}">{{info.user.id}}</a></td>
      </tr>
      <tr>
        <td>Created:</td>
        <td>{{ info.user.created|fmtdatetime }} UTC</td>
      <tr>
        <td>Full Name:</td>
        <td><input name="full_name" value="{{info.user.full_name}}" size="50" tabindex="1" /></td>
        <td/>
      </tr>
      <tr>
        <td>E-Mail:</td>
        <td><input name="email" value="{{info.user.email}}" size="50" tabindex="2" /></td>
        <td/>
      </tr>
      <tr>
        <td>URL:</td>
        <td><input name="url" id="url" value="{{info.user.url}}" size="50" tabindex="3" /></td>
        <td id="urltest" />
      </td>
      <tr>
        <td>About You:</td>
        <td><textarea name="about" rows="4" cols="50" tabindex="4">{{info.user.about}}</textarea></td>
        <td/>
      </tr>
        <tr><td colspan="3" class="spacing" /></tr>
      <tr>
        <td/><td colspan="2">
          <button type="submit" tabindex="5">Save</button>
        </td>
      </tr>
    </table>
  </form>
{% endif %}

{# this script constructs a url and shows it as a link, just for testing #}
<script type="text/javascript">
function makelink() {
   var url = $("#url").val();
   if (url.substring(0,7) != "http://" && url.substring(0,8) != "https://") {
     url = "http://" + url;  
   }
   $("#urltest").html("<a href='" + url + "' target='_blank'>test</a>");
}

$(function() {
   $("#url").keyup(function(evt) { evt.preventDefault(); makelink()});
});
makelink();
</script>

{% endblock %}


